1 module hip.api.renderer.core; 2 public import hip.api.input.window; 3 public import hip.api.renderer.vertex; 4 public import hip.api.renderer.operations; 5 public import hip.api.renderer.viewport; 6 public import hip.api.renderer.texture; 7 public import hip.api.renderer.framebuffer; 8 public import hip.api.renderer.shader; 9 public import hip.api.renderer.shadervar; 10 11 12 ///Could later be moved to windowing 13 enum HipWindowMode : ubyte 14 { 15 windowed, 16 fullscreen, 17 borderlessFullscreen 18 } 19 20 21 /** 22 * Maybe should not be used in user facing api. 23 */ 24 pragma(LDC_no_typeinfo) 25 struct DefaultShader 26 { 27 ///Path on where the shaders are stored. 28 string path; 29 ///Vertex Source 30 string function() vSource; 31 ///Fragment Source 32 string function() fSource; 33 } 34 35 pragma(LDC_no_typeinfo) 36 struct HipRendererInfo 37 { 38 HipRendererType type; 39 size_t function(ShaderTypes, UniformType) uniformMapper; 40 } 41 42 ///Which API is being used 43 enum HipRendererType : ubyte 44 { 45 GL3, 46 D3D11, 47 Metal, 48 None 49 } 50 51 52 /// Primitive which the renderer will use 53 enum HipRendererMode : ubyte 54 { 55 point, 56 line, 57 lineStrip, 58 triangles, 59 triangleStrip 60 } 61 62 63 64 65 //////////////////////////////////////////Metadata////////////////////////////////////////// 66 67 //Shaders 68 enum HipShaderInputLayout; 69 /** 70 * Use this special UDA to say this type is only for accumulating stride and thus should not 71 * be defined on shader 72 */ 73 enum HipShaderInputPadding; 74 /** 75 * Declares that the struct is as VertexUniform block. 76 */ 77 pragma(LDC_no_typeinfo) 78 struct HipShaderVertexUniform 79 { 80 /** 81 * This name is the base uniform name accessed when dealing with HLSL Api. 82 * i.e: Constant Buffer block name 83 */ 84 string name; 85 } 86 /** 87 * Declares that the struct is as FragmentUniform block. 88 */ 89 pragma(LDC_no_typeinfo) 90 struct HipShaderFragmentUniform 91 { 92 /** 93 * This name is the base uniform name accessed when dealing with HLSL Api. 94 * i.e: Constant Buffer block name 95 */ 96 string name; 97 } 98 99 /** 100 * Minimal interface for another API implementation 101 */ 102 interface IHipRendererImpl 103 { 104 public bool init(IHipWindow window); 105 version(dll){public bool initExternal();} 106 public bool isRowMajor(); 107 void setErrorCheckingEnabled(bool enable = true); 108 public IShader createShader(); 109 size_t function(ShaderTypes shaderType, UniformType uniformType) getShaderVarMapper(); 110 public IHipFrameBuffer createFrameBuffer(int width, int height); 111 public IHipVertexArrayImpl createVertexArray(); 112 public IHipRendererBuffer createBuffer(size_t size, HipResourceUsage usage, HipRendererBufferType type); 113 public IHipTexture createTexture(HipResourceUsage usage); 114 public int queryMaxSupportedPixelShaderTextures(); 115 public void setColor(ubyte r = 255, ubyte g = 255, ubyte b = 255, ubyte a = 255); 116 public void setViewport(Viewport v); 117 public bool setWindowMode(HipWindowMode mode); 118 public void setDepthTestingEnabled(bool); 119 public void setDepthTestingFunction(HipDepthTestingFunction); 120 public void setStencilTestingEnabled(bool); 121 public void setStencilTestingMask(uint mask); 122 public void setColorMask(ubyte r, ubyte g, ubyte b, ubyte a); 123 ///When pass func evaluates to true, then it is said to be passed 124 public void setStencilTestingFunction(HipStencilTestingFunction passFunc, uint reference, uint mask); 125 public void setStencilOperation(HipStencilOperation stencilFail, HipStencilOperation depthFail, HipStencilOperation stencilAndDephPass); 126 public bool hasErrorOccurred(out string err, string line = __FILE__, size_t line =__LINE__); 127 public void begin(); 128 public void setRendererMode(HipRendererMode mode); 129 public void drawIndexed(index_t count, uint offset = 0); 130 public void drawVertices(index_t count, uint offset = 0); 131 public void end(); 132 public void clear(); 133 public void clear(ubyte r = 255, ubyte g = 255, ubyte b = 255, ubyte a = 255); 134 public void dispose(); 135 } 136 137 interface IHipRenderer 138 { 139 ///Gets which renderer type it is 140 HipRendererType getType(); 141 HipRendererInfo getInfo(); 142 143 int getMaxSupportedShaderTextures(); 144 IHipTexture getTextureImplementation(HipResourceUsage usage = HipResourceUsage.Immutable); 145 Viewport getCurrentViewport() @nogc; 146 void setViewport(Viewport v); 147 IHipVertexArrayImpl createVertexArray(); 148 IHipRendererBuffer createBuffer(size_t size, HipResourceUsage usage, HipRendererBufferType type); 149 150 void setRendererMode(HipRendererMode); 151 HipRendererMode getMode(); 152 void drawIndexed(index_t count, uint offset = 0); 153 void drawIndexed(HipRendererMode mode, index_t count, uint offset = 0); 154 void drawVertices(index_t count, uint offset = 0); 155 void drawVertices(HipRendererMode mode, index_t count, uint offset = 0); 156 void end(); 157 void clear(HipColorf color); 158 HipDepthTestingFunction getDepthTestingFunction() const; 159 bool isDepthTestingEnabled() const; 160 void setDepthTestingEnabled(bool bEnable); 161 void setDepthTestingFunction(HipDepthTestingFunction); 162 void setStencilTestingEnabled(bool bEnable); 163 void setStencilTestingMask(uint mask); 164 void setColorMask(ubyte r, ubyte g, ubyte b, ubyte a); 165 void setStencilTestingFunction(HipStencilTestingFunction passFunc, uint reference, uint mask); 166 void dispose(); 167 168 } 169 170 171 private __gshared IHipRenderer _renderer; 172 void setHipRenderer(IHipRenderer r) 173 { 174 _renderer = r; 175 } 176 177 IHipRenderer HipRenderer() 178 { 179 return _renderer; 180 }